package cn.dengta.webapp.im.entity;

import java.util.Date;
import javax.annotation.Nullable;

import cn.dengta.common.model.*;
import cn.dengta.common.util.Common;
import cn.dengta.context.model.Language;
import cn.dengta.webapp.base.entity.TimeBasedEntity;
import cn.dengta.webapp.user.vo.AudioVO;
import cn.dengta.webapp.user.vo.VideoVO;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.StringUtil;
import me.codeplayer.util.X;

@Setter
@Getter
@Accessors(chain = true)
@TableName("im_greet_text")
public class GreetText extends TimeBasedEntity {

	/** 类型：0=搭讪；1=快捷回复 */
	private GreetTextType type;
	/** 性别：0=女；1=男 */
	private Integer gender;
	/** 招呼内容 */
	private String content;
	private Language language;
	private Integer status;
	private Integer sort;
	private Integer useCount;
	private Integer replyCount;
	private transient String image;
	private transient AudioVO audioVO;
	private transient VideoVO videoVO;
	/** 是否是自定义搭讪语 */
	private transient boolean customize;

	public GreetText init(GreetText input, Date now) {
		this.content = StringUtil.toString(input.content);
		this.gender = X.expectNotNull(input.gender, gender);
		this.type = X.expectNotNull(type, input.type, GreetTextType.GREET);
		this.language = input.language;
		this.replyCount = 0;
		this.useCount = 0;
		this.sort = X.expectNotNull(input.sort, sort, 0);
		this.status = X.expectNotNull(input.status, status, Status.YES.value);
		super.initTime(now);
		return this;
	}

	@Getter
	public enum GreetTextType implements ValueProxyImpl<GreetTextType, Integer> {

		/** 搭讪语 */
		GREET(0, "搭讪语"),
		/** 快捷回复 */
		SPEED_REPLY(1, "快捷回复"),
		/** 牵线 */
		USER_PULL(2, "牵线"),
		/** 双向牵线 */
		DOUBLE_USER_PULL(3, "双向牵线"),
		//
		;

		// 定义私有变量
		public final Integer value;
		final ValueProxy<GreetTextType, Integer> proxy;

		// 构造函数，枚举类型只能为私有
		GreetTextType(Integer value, String label) {
			this.value = value;
			this.proxy = new ValueProxy<>(this, value, label);
		}

		public static final GreetTextType[] CACHE = values();

		public static GreetTextType of(@Nullable Integer value) {
			return Common.getEnum(CACHE, GreetTextType::getValue, value);
		}

	}

	public static final String GENDER = "gender";
	public static final String TYPE = "type";
	public static final String CONTENT = "content";
	public static final String LANGUAGE = "language";
	public static final String SORT = "sort";
	public static final String STATUS = "status";

}
